//
//  CalculatorButtonModel.swift
//  SwiftUI-Calculator
//
//  Created by gree on 2020/9/27.
//
import SwiftUI

enum CalculatorButtonItem: Hashable {
    enum Op: String {
        /// +
        case plus = "+"
        /// -
        case minus = "-"
        /// ÷
        case divide = "÷"
        /// x
        case multiply = "x"
        /// =
        case equal = "="
    }
    
    enum Command: String {
        /// AC 清除
        case clear = "AC"
        case flip = "+/-"
        case percent = "%"
    }
    /// 数字
    case digit(Int)
    /// 小数点
    case dot
    /// 操作
    case op(Op)
    /// 符号翻转
    case command(Command)
}

extension CalculatorButtonItem {
    var title: String {
        switch self {
            case .digit(let value):
                return String(value)
            case .dot:
                return "."
            case .op(let op):
                return op.rawValue
            case .command(let command):
                return command.rawValue
        }
    }
    
    var size: CGSize {
        if case .digit(let value) = self, value == 0 {
            return CGSize(width: 88*2+8, height: 88)
        }
        return CGSize(width: 88, height: 88)
    }
    
    var backgroundColor: Color {
        switch self {
            case .digit, .dot:
                return .digitColor
            case .op:
                return .operatorColor
            case .command:
                return .commandColor
        }
    }
    
}
